<include file="Layout/header" />
<div class="mws-panel grid_8">
    <div class="mws-panel-header">
        <span><i class="icon-table"></i> 文章管理</span>
    </div>
    <div class="mws-panel-body no-padding">
        <div class="dataTables_wrapper">
            <form method="get" id="form">
                <div class="dataTables_filter">
                    <label>关键字<input type="text" name="title"></label>
                    <button type="submit"  class="btn btn-primary">确定</button>
                </div>
            </form>
            <table class="mws-datatable-fn mws-table" id="list">
                <thead>
                    <tr>
                        <th>顶置</th>
                        <th>ID</th>
                        <th>所属栏目</th>
                        <th>标题</th>
                        <th>作者</th>
                        <th>原创</th>
                        <th>显示</th>
                        <th>点击数</th>
                        <th>发布时间</th>
                        <th>操作</th>
                    </tr>
                </thead>
                <tbody>
                </tbody>
            </table>
        </div>
    </div>
</div>
<script type="text/javascript">

    $(document).ajaxStart(function () {
        index = layer.load();
    }).ajaxStop(function () {
        layer.close(index);
    });

    var oTable = $('#list').dataTable({
        "bJQueryUI": false,
        "sDom": 'rt<i>flp',
        "bProcessing": false,
        "bServerSide": true,
        "autoWidth": false,
        "sAjaxSource": '/index.php?m=Admin&c=Article&a=lists',
        "bFilter": false, //过滤功能
        "bSort": false, //排序功能
        "bPaginate": true, //翻页功能
        "bLengthChange": true, //改变每页显示数据数量
        "sPaginationType": "full_numbers",
        "iDisplayLength": 15, // 每页显示行数  
        "aLengthMenu": [[15, 50, 100],
            ["15条", "50条", "100条"]],
        "oLanguage": {
            "sLengthMenu": "每页显示 _MENU_ 条记录",
            "sInfo": "从 _START_ 到 _END_ /共 _TOTAL_ 条数据",
            "sInfoEmpty": "没有数据",
            "sInfoFiltered": "(从 _MAX_ 条数据中检索)",
            "sZeroRecords": "没有检索到数据",
            "sSearch": "搜索:",
            "oPaginate": {
                "sFirst": "首页",
                "sPrevious": "前一页",
                "sNext": "后一页",
                "sLast": "尾页"
            }
        },
        "aoColumns": [
            {"mData": function (data) {
                    return '<input name="is_top" style="width:35px;" data-id="'+data.id+'" type="text" value="' + data.is_top + '"/>';
                }},
            {"mData": "id"},
            {"mData": "class"},
            {"mData": function(data){
                    return '<a href="javascript:;" onclick="info('+data.id+')">'+data.title+'</a>';
                }},
            {"mData": "writer"},
            {"mData": "is_original"},
            {"mData": "is_show"},
            {"mData": "click"},
            {"mData": "addtime"},
            {"mData": function (data) {
                    return '<a href="javascript:;" class="btn btn-primary">修改</a>&nbsp;&nbsp;<a href="javascript:;" id="' + data.id + '" class="btn btn-danger del-btn">删除</a>';
                }}
        ]
        
    });

    $('#form').submit(function () {
        var oSettings = oTable.fnSettings();
        oSettings.sAjaxSource = "/index.php?m=Admin&c=Article&a=lists&" + $(this).serialize();//重新设置url
        oTable.fnDraw();
        return false;
    });


    $('input[name=is_top]').live('blur', function () {
        var is_top = $(this).val();
        var id = $(this).attr('data-id');
        var index = layer.load();
        $.ajax({
            url: "{:U('Article/is_top')}",
            type: 'get',
            dataType: 'json',
            data: {'is_top': is_top,'id':id},
            success: function (result) {
                layer.close(index);
                if (result.status == '1') {
                    //  window.location.herf = window.location.herf;
                    window.location.reload();
                } else {
                    layer.alert(result.msg, {
                        title: '提示'
                    });
                }
            }
        });

    });


    //点击查看详情
    function info(id)
    {
        
        layer.open({
            type: 2,
            title: '文章详情',
            area: ['1000px', '650px'],
            shadeClose: true,
            content: '/index.php/Admin/Article/info/id/' + id
            
        });
    }

</script>
<include file="Layout/footer" />
